package kr.hkit.androidcomplete01.chaptert07;

import kr.hkit.androidcomplete01.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;

public class ToastEx extends Activity {
	int count;
	String str;
	Toast mToast;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.ch07_toastex);
	}
	
	public void mOnClick(View v){
		switch(v.getId()){
		case R.id.toastex_btn01:
			Toast.makeText(ToastEx.this, "잠시 나타나는 메시지", Toast.LENGTH_SHORT).show();
			break;
		case R.id.toastex_btn02:
			Toast.makeText(ToastEx.this, "조금 길게 나타나는 메시지", Toast.LENGTH_LONG).show();
			break;
		case R.id.toastex_btn03:
			str = "현재 카운트 = " + count++;
			if(mToast != null){
				mToast.cancel();
			}
			mToast = Toast.makeText(ToastEx.this, str, Toast.LENGTH_LONG);
			mToast.show();
			break;
		case R.id.toastex_btn04:
			if (mToast == null){
				mToast = Toast.makeText(this, str, Toast.LENGTH_LONG);
			} else {
				mToast.setText(str);
			}
			mToast.show();
			break;
		case R.id.toastex_btn05:
			LinearLayout linear = (LinearLayout) View.inflate(this, R.layout.toastview, null);
			Toast t2 = new Toast(ToastEx.this);
			t2.setView(linear);
			t2.show();
			break;
		}
	}
}
